﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Autofac;

namespace WinFormWithAutofac
{
    public static class BootStrapper
    {
        public static IContainer AutoFacContainer;

        public static void BuildContainer()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<Form1>().PropertiesAutowired();//允许属性注入;
            var dalAssemble = Assembly.LoadFrom("Winform.DAL.dll");
            builder.RegisterAssemblyTypes(dalAssemble)
                  .AsImplementedInterfaces()
                  .InstancePerDependency() //默认模式，每次调用，都会重新实例化对象；每次请求都创建一个新的对象；
                  .PropertiesAutowired();//允许属性注入
            var bllAssemble = Assembly.LoadFrom("Winform.BLL.dll");
            builder.RegisterAssemblyTypes(bllAssemble)
                  .AsImplementedInterfaces()
                  .InstancePerDependency()
                  .PropertiesAutowired(); //允许属性注入
            AutoFacContainer = builder.Build();
        }
    }
}
